<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>

		<script type="text/javascript">
			// 让用户输出一个整数n, 求 1!+2!+3!+4!+…n!。
			let num = parseInt(prompt("请输入一个整数：")); // parseInt() 函数可解析一个字符串，并返回一个整数。 用法：parseInt(string, radix)
			let sum = 0
			for (let i = 1; i <= num; i++) {
				let factorial = 1; //1! = 1		阶乘
				for (let j = 1; j <= i; j++) {
					factorial = factorial * j;		//或者写成factorial *= j
				}
				sum += factorial;
			}
			console.log("1到" + num + "阶乘的和为：" + sum)
		</script>
	</body>
</html>
